Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
ansi-escape-sequences
Advanced tools
A simple library containing all known terminal ansi escape codes and sequences.
The ansi-escape-sequences npm package provides utilities for working with ANSI escape codes, which are used to control text formatting, color, and other output options on text terminals. This package allows you to easily add color, style, and control sequences to your terminal output.
Text Formatting
This feature allows you to format text with styles such as bold, italic, underline, etc. The code sample demonstrates how to make text bold.
const ansi = require('ansi-escape-sequences');
console.log(ansi.format('This is bold text', ['bold']));
Text Coloring
This feature allows you to colorize text with various colors. The code sample demonstrates how to make text red.
const ansi = require('ansi-escape-sequences');
console.log(ansi.format('This is red text', ['red']));
Cursor Control
This feature allows you to control the cursor position in the terminal. The code sample demonstrates how to move the cursor to a specific position before printing text.
const ansi = require('ansi-escape-sequences');
process.stdout.write(ansi.cursor.goto(10, 5));
console.log('Text at position (10, 5)');
Clearing the Screen
This feature allows you to clear parts or the entire terminal screen. The code sample demonstrates how to clear the entire screen.
const ansi = require('ansi-escape-sequences');
process.stdout.write(ansi.erase.display(2));
Chalk is a popular library for styling terminal strings. It provides a more user-friendly API for applying styles and colors to text. Compared to ansi-escape-sequences, Chalk is more focused on ease of use and readability.
Colors is another library for adding color and style to terminal output. It offers a chainable API for applying multiple styles. Compared to ansi-escape-sequences, Colors provides a more fluent interface for combining styles.
CLI-Color is a library for styling terminal output with ANSI colors and styles. It offers a comprehensive set of features for text formatting and cursor control. Compared to ansi-escape-sequences, CLI-Color provides a more extensive set of utilities for terminal manipulation.
A simple library containing all known terminal ansi escape codes and sequences. Useful for adding colour to your command-line output, or building a dynamic text user interface.
Format text in the terminal (bold red, in this case):
$ echo yeah | ansi format bold red
yeah
Example
var ansi = require('ansi-escape-sequences')
enum
string
string
string
string
string
string
string
string
string
string
string
string
enum
Various formatting styles (aka Select Graphic Rendition codes).
Kind: static enum property of ansi-escape-sequences
Properties
Name | Type | Default |
---|---|---|
reset | string | "\u001b[0m" |
bold | string | "\u001b[1m" |
italic | string | "\u001b[3m" |
underline | string | "\u001b[4m" |
fontDefault | string | "\u001b[10m" |
font2 | string | "\u001b[11m" |
font3 | string | "\u001b[12m" |
font4 | string | "\u001b[13m" |
font5 | string | "\u001b[14m" |
font6 | string | "\u001b[15m" |
imageNegative | string | "\u001b[7m" |
imagePositive | string | "\u001b[27m" |
black | string | "\u001b[30m" |
red | string | "\u001b[31m" |
green | string | "\u001b[32m" |
yellow | string | "\u001b[33m" |
blue | string | "\u001b[34m" |
magenta | string | "\u001b[35m" |
cyan | string | "\u001b[36m" |
white | string | "\u001b[37m" |
"bg-black" | string | "\u001b[40m" |
"bg-red" | string | "\u001b[41m" |
"bg-green" | string | "\u001b[42m" |
"bg-yellow" | string | "\u001b[43m" |
"bg-blue" | string | "\u001b[44m" |
"bg-magenta" | string | "\u001b[45m" |
"bg-cyan" | string | "\u001b[46m" |
"bg-white" | string | "\u001b[47m" |
Example
console.log(ansi.style.red + 'this is red' + ansi.style.reset)
cursor-related sequences
Kind: static property of ansi-escape-sequences
string
string
string
string
string
string
string
string
Hides the cursor
Kind: static property of cursor
Shows the cursor
Kind: static property of cursor
string
Moves the cursor lines
cells up. If the cursor is already at the edge of the screen, this has no effect
Kind: static method of cursor
Param | Type | Default |
---|---|---|
[lines] | number | 1 |
string
Moves the cursor lines
cells down. If the cursor is already at the edge of the screen, this has no effect
Kind: static method of cursor
Param | Type | Default |
---|---|---|
[lines] | number | 1 |
string
Moves the cursor lines
cells forward. If the cursor is already at the edge of the screen, this has no effect
Kind: static method of cursor
Param | Type | Default |
---|---|---|
[lines] | number | 1 |
string
Moves the cursor lines
cells back. If the cursor is already at the edge of the screen, this has no effect
Kind: static method of cursor
Param | Type | Default |
---|---|---|
[lines] | number | 1 |
string
Moves cursor to beginning of the line n lines down.
Kind: static method of cursor
Param | Type | Default |
---|---|---|
[lines] | number | 1 |
string
Moves cursor to beginning of the line n lines up.
Kind: static method of cursor
Param | Type | Default |
---|---|---|
[lines] | number | 1 |
string
Moves the cursor to column n.
Kind: static method of cursor
Param | Type | Description |
---|---|---|
n | number | column number |
string
Moves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted.
Kind: static method of cursor
Param | Type | Description |
---|---|---|
n | number | row number |
m | number | column number |
erase sequences
Kind: static property of ansi-escape-sequences
string
string
string
Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen.
Kind: static method of erase
Param | Type |
---|---|
n | number |
string
Erases part of the line. If n is zero (or missing), clear from cursor to the end of the line. If n is one, clear from cursor to beginning of the line. If n is two, clear entire line. Cursor position does not change.
Kind: static method of erase
Param | Type |
---|---|
n | number |
string
Returns an ansi sequence setting one or more effects
Kind: static method of ansi-escape-sequences
Param | Type | Description |
---|---|---|
effectArray | string | Array.<string> | a style, or list or styles |
Example
> ansi.styles('green')
'\u001b[32m'
> ansi.styles([ 'green', 'underline' ])
'\u001b[32;4m'
string
A convenience function, applying the provided styles to the input string and then resetting.
Inline styling can be applied using the syntax [style-list]{text to format}
, where style-list
is a space-separated list of styles from ansi.style. For example [bold white bg-red]{bold white text on a red background}
.
Kind: static method of ansi-escape-sequences
Param | Type | Description |
---|---|---|
str | string | the string to format |
[styleArray] | Array.<string> | a list of styles to add to the input string |
Example
> ansi.format('what?', 'green')
'\u001b[32mwhat?\u001b[0m'
> ansi.format('what?', ['green', 'bold'])
'\u001b[32;1mwhat?\u001b[0m'
> ansi.format('[green bold]{what?}')
'\u001b[32;1mwhat?\u001b[0m'
As a library:
$ npm install ansi-escape-sequences --save
As a command-line tool:
$ npm install -g ansi-escape-sequences
© 2015 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.
FAQs
A simple library containing all known terminal ansi escape codes and sequences.
The npm package ansi-escape-sequences receives a total of 415,628 weekly downloads. As such, ansi-escape-sequences popularity was classified as popular.
We found that ansi-escape-sequences demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.